<?php
namespace Home\Controller;
use Think\Controller;
class GoodsController extends Controller
{

    public function goods()
    {
    	$user = M('users');
    	$data['telephone']=$_SESSION['telephone'];
    	$res=$user->where(data)->find();
    	$this->list=$res;

        $goods = M('goods');
        $goodsData['userid'] =$data['telephone'];
        $qrcodeList=$goodsmodel->where($goodsData)->select;
        $this->qrcodeList=$qrcodeList;

        $goodsmodel = M('goods');
        // $goods = $goodsmodel->order('id desc')->select();
        // //var_dump($goodsmodel);
        // $this->goods = $goods;
        $this->display();
    }



        public function myupload(){
        $upload=new \Think\Upload();//实例化ThinkPhp自带上传类
        $upload->maxSize = 3145728;//设置上传附件大小
        $upload->exts = array('jpg','jpeg','png','gif');//设置附件上传类型
        $upload->rootPath = './Public/Uploads/lostphoto/';
        //$upload->savePath='';
        $upload->autoSub =false;
        
        $upload->saveName = time().'_'.mt_rand();
        $info = $upload->upload();  // 上传文件
        
        if (!$info) {
            $this->error($upload->getError());
        }
        else{
            return $info;
        }
    }
    public function dolostrelease(){
        $goods=D('lost');
        if ($goods->create()) {
            if ($_FILES['file']['error']==0) {
                $logoinfo = $this->myupload();
                $pname = $logoinfo['file']['savename'];
                /*dump($logoinfo);
                echo "$pname";
                exit;*/
            }
            else{
                $pname="default.jpg";
            } 
            $image = new \Think\Image();
            $image->open('./Public/Uploads/lostphoto/'.$pname);
            $image->thumb(150,150)->save('./Public/Uploads/lostphoto/'.$pname);
            $goods->picture=$pname;
            /*var_dump($goods);*/
            if (false!==$goods->add()){
                echo $goods->getLastSql();
                $this->success('发布成功');
            }
            else
            {
                $this->error('发布错误'); 
            }
        }
        else{
            $this->error($goods->getError());
        }
    }


  

           public function logindex(){
 
        //调用模型层获取数据
        $lostmodel = M('lost');
        //var_dump($lostmodel);
        $lost = $lostmodel->select();
        //desc倒序 asc顺序
        
        //调用视图层显示数据
        $this->lost=$lost;
        //var_dump($lost);
        $this->display();
    }   

}
